package com.jvm.interpreter;

import com.jvm.classfile.ClassLoader;
import com.jvm.classfile.model.Class;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: diy_simple_jvm
 * @description: 元空间
 * @author: CaoYong
 * @create: 2021-07-09 11:09
 **/
public abstract class MetaSpace {

    static final Map<String, Class> CLASS_MAP = new HashMap<>();

    static ExecEnv main;

    public static Class findClass(String name) {
        return CLASS_MAP.get(name);
    }

    public static void putClass(String name, Class clazz) {
        if (CLASS_MAP.containsKey(name)) {
            throw new IllegalStateException("duplicate class name," + name);
        }
        CLASS_MAP.put(name, clazz);
    }

    static ClassLoader loader;

    public static void setClassLoader(ClassLoader classLoader) {
        loader = classLoader;
    }

    public static ClassLoader getClassLoader() {
        return loader;
    }

    public static ExecEnv getMainEnv() {
        return main;
    }

    public static void putMainEnv(ExecEnv env) {
        main = env;
    }

}
